/*


 */

package jas.http.logging;

import jas.http.request.HttpRequest;
import jas.http.response.HttpResponse;
import java.io.PrintStream;
import java.net.Socket;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 *
 */
public class DateRequestLineResponseCodeIPHttpLogger implements HttpLogger {

    private DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
    private PrintStream output, errorOutput;
    
    public DateRequestLineResponseCodeIPHttpLogger(PrintStream output, PrintStream errorOutput) {
        this.output = output;
        this.errorOutput = errorOutput;
    }
    
    public void log(HttpRequest request, HttpResponse response, Socket socket) {
        output.println(dateFormat.format(new Date())+ " - " +
                request.getRequestLine() + " : " + response.getCode().toString()+
                " (" + socket.getInetAddress().getHostAddress()+":"+socket.getPort()+")");
    }
    
    public void log(String msg) {
        output.println(dateFormat.format(new Date()) + " - " + msg);
    }
    
    public void logError(String msg) {
        errorOutput.println(dateFormat.format(new Date()) + " - " + msg);
    }

}
